import { Module } from 'vuex'

import { getAddressGoodsSale, getCategoryGoodsCount , getCategoryGoodsFavor, getCategoryGoodsSale } from '@/service/main/analysis/dashboard'

import { IDsahboardState } from './type'
import { IRootState } from '../../type'

const dashboardModlue: Module<IDsahboardState,IRootState> = {
  namespaced:true,
  state(){
    return{
      categoryGoodsCount:[],
      categoryGoodsSale:[],
      categoryGoodsFavor:[],
      addressGoodsSale:[],
    }
  },
  mutations:{
    changeCategoryGoodsCount(state,list){
      state.categoryGoodsCount = list
    },
    changeCategoryGoodsSale(state,list){
      state.categoryGoodsSale = list
    },
    changeCategoryGoodsFavor(state,list){
      state.categoryGoodsFavor = list
    },
    changeAddressGoodsSale(state,list){
      state.addressGoodsSale = list
    }
  },
  actions:{
    async getDashboardDataAction({commit}){
      const categoryCountResult = await getCategoryGoodsCount()
      // console.log(categoryCountResult)
      commit('changeCategoryGoodsCount',categoryCountResult.data)

      const categorySaleResult = await getCategoryGoodsSale()
      commit('changeCategoryGoodsSale',categorySaleResult.data)

      const categoryFavorResult = await getCategoryGoodsFavor()
      commit('changeCategoryGoodsFavor',categoryFavorResult.data)

      const addressGoodsSaleResult = await getAddressGoodsSale()
      commit('changeAddressGoodsSale',addressGoodsSaleResult.data)
    }
  }
}

export default dashboardModlue
